package com.utils;

import java.util.HashSet;
import java.util.List;

import org.apache.velocity.VelocityContext;

/**
 * 模板处理工具类
 * 
 * @author 码农小鹿
 */
public class VelocityUtils {
	
	public final static String domain = "com/vm/domain.java.vm";
	public final static String domainEvent = "com/vm/domainEvent.java.vm";
	public final static String daoJava = "com/vm/dao.java.vm";
	public final static String daoXml = "com/vm/dao.xml.vm";
	public final static String mapperJava = "com/vm/mapper.java.vm";
	public final static String mapperXml = "com/vm/mapper.xml.vm";
	public final static String html = "com/vm/manage.html.vm";

	/**
	 * 设置模板变量信息
	 *
	 * @return 模板列表
	 */
	public static VelocityContext prepareContext(MysqlTable table, String author, List<String> imports) {

		VelocityContext velocityContext = new VelocityContext();
		velocityContext.put("author", author);
		velocityContext.put("datetime", StrUtil.getDate());
		velocityContext.put("columns", table.getColumns());
		velocityContext.put("table", table);
		velocityContext.put("imports", imports);
		 
		return velocityContext;
	}
	  
	/**
	 * 根据列类型获取导入包
	 * 
	 * @param genTable 业务表对象
	 * @return 返回需要导入的包列表
	 */
	public static HashSet<String> getImportList(MysqlTable table) {
		HashSet<String> importList = new HashSet<String>();
		for (MysqlColumn column : table.getColumns()) {
			if ("date".equals(column.getJavaType()) || "datetime".equals(column.getJavaType())) {
				importList.add("java.util.Date");
			} else if ("decimal".equals(column.getJavaType())) {
				importList.add("java.math.BigDecimal");
			}
		}
		return importList;
	}
}
